package com.example.pclimb.database;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.TypeConverters;

import com.example.pclimb.dao.ClimbRequestDao;
import com.example.pclimb.dao.GuideImageDao;
import com.example.pclimb.dao.ReviewDao;
import com.example.pclimb.dao.TravelGuideDao;
import com.example.pclimb.dao.UserDao;
import com.example.pclimb.dao.UserLikeDao;
import com.example.pclimb.model.ClimbRequest;
import com.example.pclimb.model.GuideImage;
import com.example.pclimb.model.Review;
import com.example.pclimb.model.TravelGuide;
import com.example.pclimb.model.User;
import com.example.pclimb.model.UserLike;
import com.example.pclimb.util.DateConverter;

/**
 * 陪爬APP的Room数据库类
 */
@Database(entities = {User.class, ClimbRequest.class, Review.class, TravelGuide.class, UserLike.class, GuideImage.class}, version = 1, exportSchema = false)
@TypeConverters({DateConverter.class})
public abstract class PclimbDatabase extends RoomDatabase {

    private static PclimbDatabase instance;

    public abstract UserDao userDao();
    public abstract ClimbRequestDao climbRequestDao();
    public abstract ReviewDao reviewDao();
    public abstract TravelGuideDao travelGuideDao();
    public abstract UserLikeDao userLikeDao();
    public abstract GuideImageDao guideImageDao();

    /**
     * 获取数据库实例（单例模式）
     */
    public static synchronized PclimbDatabase getInstance(Context context) {
        if (instance == null) {
            instance = Room.databaseBuilder(context.getApplicationContext(),
                            PclimbDatabase.class, "pclimb_database")
                    .fallbackToDestructiveMigration()
                    .build();
        }
        return instance;
    }
} 